﻿using Flurl.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using TiaoTiaoCode.AutoUpdate.Common.Dtos;
using TiaoTiaoCode.AutoUpdate.Common.Responses;
using TiaoTiaoCode.Common.Helpers;

namespace TiaoTiaoCode.AutoUpdate.ServerUI.Biz
{
    /// <summary>
    /// 应用列表通用Biz
    /// </summary>
    internal class AppListBiz
    {
        const string AppListApi = "api/ServerUI/appList";

        /// <summary>
        /// 获取应用列表
        /// </summary>
        /// <returns></returns>
        public static async Task<List<MainProgramView>> QueryAll()
        {
            var _iniFile = new TiaoTiaoIniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "setting.ini"));

            var baseApi = _iniFile.Read("application", "baseApi", String.Empty);
            var url = $"{baseApi.TrimEnd('/')}/{AppListApi}";

            var data = await url.GetJsonAsync<ApiResponse<List<MainProgramView>>>();

            return data.Data;
        }
    }
}
